using System.Collections.Generic;
using LogSystem;
using UnityEngine;

namespace Yoozoo.Gameplay.City
{
    public class RoomDataManager : MonoBehaviour
    {
        public List<RoomData> RoomDataList = new List<RoomData>();
        public Dictionary<int, RoomData> RoomDataMap = new Dictionary<int, RoomData>();

        public Dictionary<Collider, RoomData> Col2RoomMap = new Dictionary<Collider, RoomData>();

        public void InitRooms(List<RoomData> rooms)
        {
            RoomDataList = rooms;
            foreach (var room in rooms)
            {
                if (!RoomDataMap.ContainsKey(room.rID))
                {
                    RoomDataMap[room.rID] = room;

                    if (room.colliders != null)
                    {
                        foreach (var roomCollider in room.colliders)
                        {
                            Col2RoomMap[roomCollider] = room;
                        }
                    }
                }
                else
                {
                    Debug.LogError(LogModule.CityRoom,$"重复的房间ID{room.rID}",room);
                }
            }
        }



        public RoomData GetRoomData(Collider col)
        {
            RoomData roomData = null;
            if (Col2RoomMap.TryGetValue(col,out roomData))
            {
                return roomData;
            }

            return null;
        }
        
        
        public void OnDispose()
        {
            
        }

    }
}